Centos7.4配置本地yum源和阿里源并配置yum优先级 |
您所在的位置:网站首页 › centos 配置镜像源 › Centos7.4配置本地yum源和阿里源并配置yum优先级 |
一、用Centos镜像搭建本地yum源
安装完linux系统的默认yum源为centos的官方地址,在“国内的特殊环境”下使用很慢甚至无法访问,所以一般的做法都是把默认的yum源替换成aliyun的yum源或者163等国内的yum源。但是以上的方法都是需要网络的,当没有网络的时候就无法使用了,所以还有一个常用的方法就是用Centos的iso镜像搭建本地yum源,这样安装软件的速度就会飞快,缺点是可能有些需要的包文件本地里没有。
# 1.安装Centos后默认的yum源如下 [root@localhost ~]# ll /etc/yum.repos.d/ total 32 -rw-r--r--. 1 root root 1664 Dec 9 2015 CentOS-Base.repo -rw-r--r--. 1 root root 1309 Dec 9 2015 CentOS-CR.repo -rw-r--r--. 1 root root 649 Dec 9 2015 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 290 Dec 9 2015 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 Dec 9 2015 CentOS-Media.repo -rw-r--r--. 1 root root 1331 Dec 9 2015 CentOS-Sources.repo -rw-r--r--. 1 root root 1952 Dec 9 2015 CentOS-Vault.repo# 2.把默认yum源备份并建立新yum源 # 3.在虚拟机上挂在Centos镜像文件 [root@localhost ~]#mount /dev/cdrom /mnt/ mount: /dev/sr0 is write-protected, mounting read-only # 4.编写repo文件并指向镜像的挂在目录 vim bendi.repo [bash] #库名 name=bash #库名 (这一行其实可以不用写,用 yum reipolist会报个错但不影响使用) baseurl=file:///mnt/ #“源所在路径” enabled=1 #1为启动0为不启用 gpgcheck=0 #检查签名1为检测0为不检测# 5.清除缓存 [root@localhost ~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: local Cleaning up everything Cleaning up list of fastest mirrors [root@localhost ~]# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度 [rroot@localhost ~]# yum list二、把默认的CentOS yum源修改成国内的aliyun yum源
这里是:阿里云官方教程地址 # 1.下载aliyun yum源repo文件(对应自己的系统版本下载即可,需有外网) #各系统版本repo文件对应的下载操作 CentOS 6 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo CentOS 7 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo# 2.清楚缓存 [root@localhost ~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: base extras updates Cleaning up everything Cleaning up list of fastest mirrors [root@localhost ~]# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度 [root@localhost ~]# yum list三、修改yum源的优先级 ps:当既有本地yum源又有163源的时候,我们在装软件包的时候当然希望先用本地的yum源去安装,本地找不到可用的包时再使用163源去安装软件,这里就涉及到了优先级的问题,yum提供的插件yum-plugin-priorities.noarch可以解决这个问题 1.查看是否安装了yum-plugin优先级插件 [root@localhost ~]#rpm -qa | grep yum-plugin- yum-plugin-fastestmirror-1.1.31-42.el7.noarch yum-plugin-priorities-1.1.31-42.el7.noarch之前我安装过所以能查到,如果未查到请按照以下方法安装 2.安装yum-plugin-priorities.noarch插件 [root@localhost ~]#yum -y install yum-plugin-priorities.noarch 3.查看插件是否启用 [root@localhost ~]#cat /etc/yum/pluginconf.d/priorities.conf[main]enabled = 1 //1为启动 0为禁用 4.修改本地yum源优先使用 [cal] name=local baseurl=file:///mnt enabled=1 gpgcheck=0 priority=1 //在原基础上加入priority=1 ;数字越小优先级越高 //可以继续修改其他源的priority值,经测试仅配置本地源的优先级为priority=1就会优先使用本地源了
5.验证安装包的数量执行yum repolist all 可显示所有仓库包 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |